# -*- coding: utf-8 -*-
# @FileName :database.py
# @Time :2024-01-28 19:34
# author: 小燕子
import pymysql

DictCursor = pymysql.cursors.DictCursor


class Sql:
    def __init__(self, host="shop-xo.hctestedu.com",
                 port=3306,
                 user="api_test",
                 password="Aa9999!",
                 database="shopxo_hctested"
                 ):
        self.db = pymysql.connect(
            host=host,
            port=port,
            user=user,
            password=password,
            database=database,
        )
        # 私有属性的写法，其目的为了，外界不能篡改，它的对象
        self.__cursor = self.db.cursor(DictCursor)

    def execute(self, dql):
        """执行数据库语句"""
        self.__cursor.execute(dql)
        return self

    def fetchone(self):
        return self.__cursor.fetchone()

    def fetchall(self):
        return self.__cursor.fetchall()

if __name__ == '__main__':
    print(Sql().execute("select token from sxo_user where id = 33948;").fetchone())

